﻿using System.Windows.Forms;

namespace EasyIot.WinApp
{
    public class DataMgr
    {
        public static MainForm MainHandle = null;  

        public static string Serial_Lock = ""; 
        public static string ServerIP = "";
        public static int ServerPort = 0;
        public static string ApiUrl = "";

        public static LockSerialPort LockSP = new LockSerialPort();

        public static bool Open(byte board, byte channel, ref string errmsg)
        {
            return LockSP.OpenLock((byte)board, (byte)channel, ref errmsg);
        }

        public static void SetHorizontalCenter(int formWidth, Label lblContent, string msg)
        {
            lblContent.Text = msg;
            lblContent.Location = new System.Drawing.Point(((formWidth - lblContent.Width) / 2), lblContent.Location.Y); 
        }

        public static void SetDoubleBuffered(TextBoxInput txtInput)
        {
            // 设置双缓冲
            txtInput.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(txtInput, true, null);
        }    
    }
}
